<template>
    <div>
        <avue-form v-if="initSuccess" ref="form" v-model="obj" :option="option"
                   @reset-change="emptytChange"
                   @submit="submit">

        </avue-form>
    </div>
</template>

<script>

    export default {
        data() {
            return {
                obj: {},
                isIdFind: true,
                initSuccess: false,
            }
        },
        props: {
            closeDialog: [],
            uri: {},
            rowData: {},
        },
        computed: {
            option() {
                return {
                    submitBtn: true,
                    emptyBtn: true,
                    detail: true,
                    submitText: '提交',
                    emptyText: "关闭",
                    column: [
                        {
                            label: '下单人',
                            prop: 'userInfo',
                            span: 10,
                            value: this.obj.fullName != null ? this.obj.fullName : "" + "  " + this.obj.nickname != null ? this.obj.nickname : ""
                        },
                        {
                            label: '订单状态',
                            prop: 'state',
                            type: 'select',
                            span: 10,
                            dicData: this.dict.get('ORDER_STATE'),
                        },
                        {
                            label: '订单号',
                            prop: 'orderNo',
                            span: 10,
                        },
                        {
                            label: '交易号',
                            prop: 'payNo',
                            span: 10,
                        },
                        {
                            label: '单价',
                            prop: 'unitPrice',
                            span: 5,
                        },
                        {
                            label: '购买数量',
                            prop: 'num',
                            span: 5,
                        },
                        {
                            label: '总价',
                            prop: 'totalPrice',
                            span: 10,
                        },

                        {
                            label: '商品图',
                            prop: 'coverPic',
                            dataType: 'string',
                            type: 'upload',
                            listType: 'picture-img',
                            span: 10,
                            value: JSON.parse(this.obj.goodsDetails).coverPic
                        },
                        {
                            label: '商品信息',
                            prop: 'goodsDetails1',
                            type:'textarea',
                            rows:10,
                            span: 10,
                            value: JSON.parse(this.obj.goodsDetails).name + "\r\n" + JSON.parse(this.obj.goodsDetails).goodsSpecsList[0].specsName
                        },


                        {
                            label: '收货地址',
                            prop: 'addressDetails1',
                            type: 'textarea',
                            span: 10,
                            value: JSON.parse(this.obj.addressDetails).fullName + " " + JSON.parse(this.obj.addressDetails).phone
                                + "\r\n" + JSON.parse(this.obj.addressDetails).province + " " + JSON.parse(this.obj.addressDetails).city + " " + JSON.parse(this.obj.addressDetails).area
                                + "\r\n" + JSON.parse(this.obj.addressDetails).specificAddress
                        },

                        {
                            label: '物流单号',
                            type: 'textarea',
                            prop: 'logisticsNo',
                            span: 10,
                        },

                        {
                            label: '下单时间',
                            prop: 'createTime',
                            span: 10,
                        },
                        {
                            label: '支付时间',
                            prop: 'payTime',
                            span: 10,
                        },
                        {
                            label: '发货时间',
                            prop: 'deliverTime',
                            span: 10,
                        },
                        {
                            label: '完成时间',
                            prop: 'successTime',
                            span: 10,
                        },
                        {
                            label: '用户备注 ',
                            prop: 'userRemark',
                            span: 10,
                        },
                        {
                            label: '平台备注 ',
                            prop: 'platformRemark',
                            span: 10,
                        },
                    ]
                }
            }
        },
        created() {
            if (this.isIdFind) {
                this.findId(this.rowData);
            } else {
                this.obj = this.rowData;
                this.initSuccess = true;
            }
        },
        methods: {
            emptytChange() {
                this.closeDialog(false);
            },
            submit(form, done) {
                this.crud.put(this.uri.info + "/" + this.obj.id, this.obj).then((res) => {
                    console.debug(res);
                    if (res.data.code == 200) {
                        this.closeDialog(true);
                    }
                    done(form);
                }).catch(err => {
                    console.error(err);
                    done(form);
                })
            },
            findId(rowData) {
                if (rowData != null && rowData.id != null) {
                    this.crud.get(this.uri.info + "/" + rowData.id).then((res) => {
                        this.obj = res.data.data;
                        this.initSuccess = true;
                    })
                }
            }
        }
    }
</script>
